package com.atfcm.stack;

import com.sun.deploy.net.proxy.RemoveCommentReader;
import com.sun.org.apache.xml.internal.security.Init;

import java.util.Stack;

/**
 * @Author 96534
 * @create 2025/3/19 16:58
 */


public class T_1047_删除字符串中的所有相邻重复项 {
    public static String removeDuplicates(String s) {
        StringBuilder stringBuffer = new StringBuilder();
        int top = -1;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (top == -1) {
                stringBuffer.append(c);
                top++;
            } else {
                if (stringBuffer.charAt(top) == c) {
                    stringBuffer.deleteCharAt(top);
                    top--;
                } else {
                    top++;
                    stringBuffer.append(c);
                }
            }
        }
        return stringBuffer.toString();
    }

    public static void main(String[] args) {
        String a = "abbc";
        System.out.println(removeDuplicates(a));
    }

}
